﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SQLite;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SqliteTest1
{
    public class Db
    {
        public SQLiteConnection m_dbConnection;
        private DeviceTable deviceTable; // 设备表

        public Db()
        {
            Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            SqliteDB sqliteDB = config.GetSection("sqliteDB") as SqliteDB;
            string fileName = sqliteDB.FileName;

            if (!File.Exists(fileName))
            {
                SQLiteConnection.CreateFile(fileName); // "xph.sqlite"
            }

            string sqlStr = "Data Source=" +
                fileName +
                ";Version=3;";
            try
            {
                m_dbConnection = new SQLiteConnection($"Data Source = {fileName}; Version=3");
                m_dbConnection.Open();

                deviceTable = new DeviceTable(m_dbConnection);
            }
            catch (SQLiteException ex)
            {
                Console.WriteLine(ex);
            }
        }
    }
}
